﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Kokomo.PeInspector.VisualStudioAdapter
{
	/// <summary>
	/// Represents a group of properties within a project.
	/// </summary>
	/// <remarks>
	/// To create a custom property group, create a derived type
	/// that adds properties to the <see cref="Properties"/> list.
	/// </remarks>
	/// <seealso cref="BasicPropertyGroup"/>
	/// <seealso cref="BuildPropertyGroup"/>
	public class PropertyGroup : IXmlSerializable
	{
		/// <summary>
		/// Initializes a new instance of <see cref="PropertyGroup"/>.
		/// </summary>
		public PropertyGroup()
		{
			this.Properties = new List<Property>();
		}

		/// <summary>
		/// Gets the condition of the property group.
		/// </summary>
		/// <remarks>
		/// The condition determines when the properties within the group
		/// become effective.
		/// </remarks>
		public string Condition { get; set; }

		/// <summary>
		/// Gets the properties within the property group.
		/// </summary>
		protected internal List<Property> Properties { get; private set; }

		System.Xml.Schema.XmlSchema IXmlSerializable.GetSchema()
		{
			return null;
		}

		void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
		{
			throw new NotImplementedException();
		}

		void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
		{
			if (this.Condition != null)
			{
				writer.WriteAttributeString("Condition", this.Condition);
			}

			XmlSerializer serializer = new XmlSerializer(typeof(Property));
			foreach (var property in this.Properties)
			{
				serializer.Serialize(writer, property);
			}
		}
	}
}
